var MessageModule = function () {
    var editable = function () {

        return {
            init: function () {
            	//表格初始化
                var oTable = $('#messageEditable').dataTable({
                    "lengthMenu": [
                        [10, 15, 20, 50],
                        [10, 15, 20, 50]
                    ],
                    "autoWidth":false,
                    "displayLength": 10,
                    "language": {
                        "lengthMenu": "每页 _MENU_ 条记录",
                        "zeroRecords":"数据为空",
                        "paginate": {
                            "previous": "上一页",
                            "next": "下一页"
                        },
                        "info" : "从 _START_ 到  _END_ 条，总记录为 _TOTAL_ 条",    
                        "infoEmpty" : "记录数为0",
                    },
                    "columnDefs": [
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "Edit",
						    "targets": [2]
						}            
                    ],
                    "columns": [
                       { "data": "name" ,'sortable': false,"defaultContent": "" },
                       { "data": "content" ,'sortable': false,"defaultContent": "" },
                   ],
                   "filter" : false,
                   "processing": false,
                   "serverSide": true,
                   "ajaxSource": ctx + "/message/list",
                   "serverMethod": "post",
                   "fnRowCallback" : function(nRow, aData, displayIndex) {
                	   nRow.children[0].id = aData.id;
                	   var operation = "";
                	   operation = '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>';
                	   $('td:eq(2)', nRow).html(operation);
                       return nRow;
                   },
                   "fnServerData" : function(ajaxSource, dataSet, fnCallback) {
	                   var json = "";
	                   var s;
	                   for (var i = 0; i < dataSet.length; i++) {
	                       s = dataSet[i];
	                   	   if (s.name == 'sEcho') {
	                   		   json = json + '"echo":' + s.value;
		                   } else if (s.name == 'iDisplayStart') {
		                	   json = json + ',"start":' + s.value;
		                   } else if (s.name == 'iDisplayLength') {
		                	   json = json + ',"pageSize":' + s.value;
		                   }
	                   }
	                   var orgId = $("#org_id").attr("value");
	                   var form = $("form#queryForm").serializeJSON();
                   	   var js = form.replace('}', '');
                   	   json = js + json +',"orgId":"'+orgId+ '"}';
                       $.ajax({
                       	"contentType":"application/json; charset=UTF-8",
                           "dataType" : 'json',
                           "type" : "POST",
                           "url" : ajaxSource,
                           "data" : json,
                           "success" : fnCallback
                       });
                   },
                });
                
                //查询
                $('#queryBtn').click(function(){
                	oTable.fnClearTable();
                });
                // 操作结束
            }

        };

    }();
    
    return {
        init: function () {
        	editable.init();
        }
    };
}();